import React from 'react';
import { Redirect, ConnectProps } from 'umi';
import { stringify } from 'querystring';
import Global from '@/global';

interface SecurityLayoutProps extends ConnectProps {
}

interface SecurityLayoutState {
}

class SecurityLayout extends React.Component<SecurityLayoutProps, SecurityLayoutState> {

  render() {
    const { children } = this.props;
    const isLogin = Global.getItem("login");
    const queryString = stringify({
      redirect: window.location.href,
    });

    if (!isLogin && window.location.pathname !== '/user/login') {
      return <Redirect to={`/user/login?${queryString}`} />;
    }
    return children;
  }
}

export default SecurityLayout;
